package crp.services.api.graphql.loaders;

import com.qwlabs.lang.C2;
import crp.services.api.graphql.models.NewsArticlePayload;
import crp.services.api.graphql.models.StorageObjectPayload;
import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Source;

import javax.enterprise.context.RequestScoped;
import java.util.List;

@GraphQLApi
@RequestScoped
public class NewsArticlePayloadLoader {

    public List<StorageObjectPayload> cover(@Source List<NewsArticlePayload> articles) {
        return C2.list(articles, article -> StorageObjectPayload.of(article.getCover()));
    }
}
